package com.nk.web;

import com.nk.domain.AjaxRes;
import com.nk.domain.Menu;
import com.nk.domain.PageListRes;
import com.nk.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class MenuController {

    @Autowired
    private MenuService menuService;

    @RequestMapping("menu")
    public String menuClick(){

        return "menu";
    }

    @RequestMapping("menuList")
    @ResponseBody
    public PageListRes menuList(){
        return menuService.getMenuList();
    }

    @RequestMapping("getMenus")
    @ResponseBody
    public List<Menu> getMenus(){
        return menuService.getMenus();
    }

    @RequestMapping("saveMenu")
    @ResponseBody
    public AjaxRes saveMenu(Menu menu){
        return menuService.saveMenu(menu);
    }

    @RequestMapping("updateMenu")
    @ResponseBody
    public AjaxRes updateMenu(Menu menu){
        return menuService.updateMenu(menu);
    }

    @RequestMapping("deleteMenu")
    @ResponseBody
    public AjaxRes deleteMenu(Long id){
        return menuService.deleteMenu(id);
    }

    @RequestMapping("getMenuTree")
    @ResponseBody
    public List<Menu> getMenuTree(){
        return menuService.getMenuTree();
    }
}
